﻿namespace Sai.Test
{
	using System.IO;
	using System.Xml.Serialization;
	using Sai.Core;
	using Sai.Test.TestDataBuilders;
	using Xunit;
    using Sai.Test.XUnit;
	
	public class ProductReleaseDifferenceFacts
	{
		public class TheAsXmlMethod
		{
			
			[Fact, InMemoryTest]
			public void Creates_MultiLine_Format()
			{
				var factory = new ProductReleaseDifferenceFactory("TestProduct", "V1", "V2");
				var releaseDifference = factory.Create();

				releaseDifference.Added(ProductAssemblyBuilder.ProductAssembly()
									.Named("NewAssembly")
									.Build());

				releaseDifference.Removed(ProductAssemblyBuilder.ProductAssembly()
									.Named("OldAssembly")
									.Build());

				releaseDifference.Changed(ProductAssemblyBuilder.ProductAssembly()
									.Named("ChangedAssembly1")
									.Build());

				releaseDifference.Changed(ProductAssemblyBuilder.ProductAssembly()
									.Named("ChangedAssembly2")
									.Build());

                releaseDifference.PercentChurn = 10;
				string output = releaseDifference.ToXml();

				Assert.Contains("<ReleaseDifference ", output);
				Assert.Contains(" ID=", output);
				Assert.Contains(" Name=\"TestProduct\"", output);
				Assert.Contains(" From=\"V1\"", output);
				Assert.Contains(" To=\"V2\"", output);
                Assert.Contains(" PercentChurn=\"10\"", output);
				Assert.Contains("<AddedAssemblies>", output);
				Assert.Contains("<ChangedAssemblies>", output);
				Assert.Contains("<RemovedAssemblies>", output);
				Assert.Contains("<Assembly ", output);
				Assert.Contains(" Name=\"NewAssembly\" />", output);
				Assert.Contains(" Name=\"OldAssembly\" />", output);
				Assert.Contains(" Name=\"ChangedAssembly1\" />", output);
				Assert.Contains(" Name=\"ChangedAssembly2\" />", output);
				Assert.Contains("</AddedAssemblies>", output);
				Assert.Contains("</ChangedAssemblies>", output);
				Assert.Contains("</RemovedAssemblies>", output);
			}
		}
	}
}
